package gochat

import (
	"log"
	"net/http"
	"sync"
)


type Options struct {
	port string
	debug bool
}
type Option func(*Options)
type GoChat struct {
	opts Options
	once sync.Once
}

func NewGoChat(opts ...Option) *GoChat {
	options := Options{}
	for _, o := range opts {
		o(&options)
	}
	return &GoChat{
		opts: options,
	}
}

// Port
func Port(arg string) Option {
	return func(o *Options) {
		o.port = arg
	}
}
// Debug
func Debug(arg bool) Option {
	return func(o *Options) {
		o.debug = arg
	}
}

func (g *GoChat) Run() {
	log.Println(g.opts)

	// http部分
	http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

	}))

	// ws部分
	//http.Handle("/ws", websocket.Handler(Echo))
	http.Handle("/ws", WsHandler())

	log.Printf("ws接口 ws://localhost/ws%s\n", g.opts.port)
	if err := http.ListenAndServe( g.opts.port, nil); err != nil {
		log.Fatal("ListenAndServer: ", err)
	}
}

type Users struct {

}

